<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;

class GetScore
{
    public function __construct()
    {

    }
    protected function script()
    {
        return <<<SCRIPT
        $('.getScore').click(function(){
            var index = layer.load(1);
            var that = this;
            var oid = $(that).attr('data-oid');
            $.ajax({
                url: '/api/cron/get/failscore?oid='+oid,
                type: 'get',
                success: function(res){
                   layer.close(index);
                   $(that).html(res.score).css('cssText', 'background-color: #fff !important;color: red !important;');
                }
            });
        });
SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());
        return '';
    }

    public function __toString()
    {
        return $this->render();
    }
}